<?php
/*
  $Id: checkout_success.php,v 1.3 2005/08/18 13:06:35 mwithington Exp $

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License
  ECJC116 Not ready Gift voucher
*/

  // -- webMS Modification --
  // Ensure a valid runtime environment or die
  if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );

  // -- webMS Modification --
  // Check if osCommerce environment is already loaded
  if (defined( '_OSCOMMERCE_LOADED' )) {
    if (!DB_SHARED) {
      // Reconnect to osCommerce Database
      tep_db_connect() or die('Unable to connect to database server!');
    }
    // Load osCommerce Globals for Boxes
    global $category_links, $languages_id, $catID, $catID_array, $current_category_id;
    global $request_type, $lng, $cart, $currencies, $language, $navigation, $breadcrumb;
  } else {
    // Load osCommerce Environment for the First Time
    require('components/'.$option.'/includes/application_top.php');
  }

  require(DIR_WS_LANGUAGES . $language . '/' . $osMod . '.php');

// if the customer is not logged on, redirect them to the shopping cart page
  if (!tep_session_is_registered('customer_id') && $ecjc_pwa !=1) {
    tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));
  }

  if (isset($_REQUEST['action']) && ($_REQUEST['action'] == 'update')) {
  //  $notify_string = 'action=notify&';
  //  $notify = $_REQUEST['notify'];
  //  if (!is_array($notify)) $notify = array($notify);
   // for ($i=0, $n=sizeof($notify); $i<$n; $i++) {
  //    $notify_string .= 'notify[]=' . $notify[$i] . '&';
  $notify_string = ''; 
    
       if (isset($_POST['notify'])) { 
         $notify = $_POST['notify']; 
    
         if (!is_array($notify)) { 
           $notify = array($notify); 
         } 

    
         for ($i=0, $n=sizeof($notify); $i<$n; $i++) { 

           if (is_numeric($notify[$i])) { 
             $notify_string .= 'notify[]=' . $notify[$i] . '&'; 

           } 
         } 
    
         if (!empty($notify_string)) { 
           $notify_string = 'action=notify&' . substr($notify_string, 0, -1); 

         } 
 

    }
   // if (strlen($notify_string) > 0) $notify_string = substr($notify_string, 0, -1);


    tep_redirect(tep_href_link(FILENAME_DEFAULT). "&$notify_string");
  }

  $breadcrumb->add(NAVBAR_TITLE_1);
  $breadcrumb->add(NAVBAR_TITLE_2);

  $global_query = tep_db_query("select global_product_notifications from " . TABLE_CUSTOMERS_INFO . " where customers_info_id = '" . (int)$customer_id . "'");
  $global = tep_db_fetch_array($global_query);

  if ($global['global_product_notifications'] != '1') {
    $orders_query = tep_db_query("select orders_id from " . TABLE_ORDERS . " where customers_id = '" . (int)$customer_id . "' order by date_purchased desc limit 1");
    $orders = tep_db_fetch_array($orders_query);

    $products_array = array();
    $products_query = tep_db_query("select products_id, products_name from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$orders['orders_id'] . "' order by products_name");
    while ($products = tep_db_fetch_array($products_query)) {
      $products_array[] = array('id' => $products['products_id'],
                                'text' => $products['products_name']);
    }
  }

require(WS_TEMPLATES . E_TEMPLATE_FOLDER . '/'.$osMod.'.html');
require(DIR_WS_INCLUDES . 'footer.php');
require(DIR_WS_INCLUDES . 'application_bottom.php');

  if (!DB_SHARED) {
    global $database, $mosConfig_host, $mosConfig_user, $mosConfig_password, $mosConfig_db, $mosConfig_dbprefix;
    $database = new database( $mosConfig_host, $mosConfig_user, $mosConfig_password, $mosConfig_db, $mosConfig_dbprefix );
  }
 ?>
